/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.dbdir.core;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.dbdir.Server;

/**
 *
 * @author Owner
 */
public class ConfigParser {

    private FileInputStream propFileStream;
    private Properties prop;
    private Server server;

    public ConfigParser(Server server) {
        this.server = server;
    }

    public Properties getConfig(String filename) {
        try {
            propFileStream = new FileInputStream(filename);
            return readStream(propFileStream);
        } catch (FileNotFoundException ex) {
            server.getLog().log(2, ex.getMessage());
            return null;
        }
    }

    public Properties getConfig(File configFile) {
        try {
            propFileStream = new FileInputStream(configFile);
            return readStream(propFileStream);
        } catch (FileNotFoundException ex) {
            server.getLog().log(2, ex.getMessage());
            return null;
        }
    }

    public Properties readStream(FileInputStream stream) {
        try {
            prop = new Properties();
            prop.load(stream);
            return prop;
        } catch (IOException ex) {
            server.getLog().log(2, ex.getMessage());
            return null;
        }
    }
}
